package com.zr.config;

import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

import java.security.SecureRandom;

/**
 * @author: peterChen
 * @date: 2019/4/17 15:33
 * @description: 加密配置类
 * @version: 1.0
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "zr.encoder.crypt")
public class PasswordConfig   {
    private int strength;
    private String secret;

    @Bean
    public BCryptPasswordEncoder passwordEncoder(){
        //利用密钥生成随机安全码
        SecureRandom secureRandom = new SecureRandom(secret.getBytes());
        return new BCryptPasswordEncoder(strength,secureRandom);
    }
}